﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FakeFreezeApp
{
    public class AutoCloseForm : Form
    {
        private System.Windows.Forms.Timer _timer;
        private Label _label;

        private void InitializeComponent()
        {
            SuspendLayout();
            // 
            // AutoCloseForm
            // 
            ClientSize = new Size(164, 81);
            Name = "AutoCloseForm";
            ResumeLayout(false);
        }

        public AutoCloseForm(string message, string title, int durationMs)
        {
            this.Text = title;
            this.Size = new Size(180, 120);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Icon = new Icon("shield.ico"); // 加载自定义图标

            _label = new Label
            {
                Text = message,
                Dock = DockStyle.Fill,
                TextAlign = ContentAlignment.MiddleCenter
            };
            this.Controls.Add(_label);

            _timer = new System.Windows.Forms.Timer();
            _timer.Interval = durationMs; // 传入的自动关闭时长
            _timer.Tick += (s, e) =>
            {
                _timer.Stop();
                this.Close();  // 直接关闭窗口
            };
            _timer.Start();
        }
    }

}
